# -*- coding: utf-8 -*-
import requests


class Base(object):

    def __init__(self):
        self.client_json = {
            'client_id': 'e93f7805dc3621c949ac',
            'client_secret': '9604ca4720a7adf84774b51ec55c849d9c530bad'
        }

    def get_code(self):
        response = requests.post('https://cloud.minapp.com/api/oauth2/hydrogen/openapi/authorize/',
                                 json=self.client_json)
        return response.json().get('code')

    def get_token(self):
        code = self.get_code()
        token_json = {
            'client_id': 'e93f7805dc3621c949ac',
            'client_secret': '9604ca4720a7adf84774b51ec55c849d9c530bad',
            'code': code,
            'grant_type': 'authorization_code'
        }
        response = requests.post('https://cloud.minapp.com/api/oauth2/access_token/',
                                 json=token_json)
        return response.json().get('access_token')

b = Base()